/**
 * The Community Project
 * Copyright Team1 Productions
 * 
 * Joshua Amick
 * Stephen Cunningham
 * Thema Davis
 * Tomika Dawson
 * Lucie DeCristofaro
 * 
 * All Rights Reserved.
 */

package com.util;

import java.sql.Timestamp;
import java.util.Date;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.business.PrivateManager;
import com.business.global.BusinessManager;
import com.constants.UserPermissions;
import com.domain.User;

public class InitData extends Task {
	private ClassPathXmlApplicationContext appContext;

	private BusinessManager biz;

	private String configFilePath;

	public String getConfigFilePath() {
		return configFilePath;
	}

	public void setConfigFilePath(String configFilePath) {
		this.configFilePath = configFilePath;
	}

	public void execute() throws BuildException {
		try {
			initData();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BuildException(e);
		}
	}

	public void initData() throws Exception {
		appContext = new ClassPathXmlApplicationContext(new String[] {
		"applicationContext.xml"});
		biz = (BusinessManager) appContext.getBean("businessMgr");
		PrivateManager privateMgr = biz.getPrivateMgr();
		Timestamp now = new Timestamp(new Date().getTime());
		System.out.println("XXXXXXXXXXXXXXXXXXXXXXX STARTING INSERTIONS XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
		User root = privateMgr.getUserDAO().saveUser(null, "root", null, "amickj@gmail.com", null, 
				"root", UserPermissions.ADMIN, null, false, true);
		
//		privateMgr.saveUser("testUser0", root, "amickj@gmail.com", root, "community", UserPermissions.PUBLIC, 
//				false, true, "Test0", "User0", "123 Some St.", "", "Columbia", "South Carolina", "29201", "", 
//				"803-777-7777", "USC", "Student", now, "BS", "Computer Science", now, 
//				"", "", true);
//		
//		privateMgr.saveUser("testUser1", root, "amickj@gmail.com", root, "community", UserPermissions.PUBLIC, 
//				false, true, "Test1", "User1", "123 Some St.", "", "Columbia", "South Carolina", "29201", "", 
//				"803-777-7777", "USC", "Student", now, "BS", "Computer Science", now, 
//				"", "", true);
//		
//		privateMgr.saveUser("testUser2", root, "amickj@gmail.com", root, "community", UserPermissions.PUBLIC, 
//				false, true, "Test2", "User2", "123 Some St.", "", "Columbia", "South Carolina", "29201", "", 
//				"803-777-7777", "USC", "Student", now, "BS", "Computer Science", now, 
//				"", "", true);
		
		System.out.println("XXXXXXXXXXXXXXXXXXXXXXX ENDING INSERTIONS XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
	}
	
}

